import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { UserConfigExport, ConfigEnv } from 'vite'
import { viteMockServe } from 'vite-plugin-mock'
import { visualizer } from "rollup-plugin-visualizer";
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ command,mode }) => {
  let env = loadEnv(mode,process.cwd());
   console.log(env);
   
  return {

     
    plugins: [vue(),
      visualizer({
        open: true,
      }),
    viteMockServe({
    // enable: command === 'serve',
    }),
    createSvgIconsPlugin({
      // Specify the icon folder to be cached
      iconDirs: [path.resolve(process.cwd(), './src/assets/icons')],
      // Specify symbolId format
      symbolId: 'icon-[dir]-[name]',
    })],
    resolve: {
      alias: {
        "@": path.resolve("./src") // 相对路径别名配置，使用 @ 代替 src
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    // 代理跨域
    server: {
      proxy: {
        
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_APP_SERVE,
          // 需要代理跨域
          changeOrigin:true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    }
  }


}
)
